/*
 * Fonti stackoverflow.com
 * http://stackoverflow.com/questions/7094121/java-serial-communication-using-javax-comm-and-saving-variables-into-an-array
 */

import java.util.Enumeration;
import javax.comm.CommPortIdentifier;

public class PortAccess {
    CommPortIdentifier commPortIdentifier;
    Enumeration enumeration;

    public void fnListPorts() {
        try {
            enumeration = CommPortIdentifier.getPortIdentifiers();
        } catch (Exception e) {
            e.printStackTrace();
        }

        while (enumeration.hasMoreElements()) {
            commPortIdentifier = (CommPortIdentifier) enumeration.nextElement();
            System.out.println(commPortIdentifier.getName());
        }
    }

    public static void main(String[] args) {
        PortAccess portAccess = new PortAccess();
        portAccess.fnListPorts();
    }
}